//
//  YStaticCell.m
//  MUBATE
//
//  Created by sunbin on 2017/2/18.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "YStaticCell.h"
#import "HeaderFooterView.h"

#define HeaderFooterViewIdentifier @"HeaderFooterViewIdentifier"
@interface YStaticCell ()

@end

@implementation YStaticCell

- (instancetype)init
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self)
    {}
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    WEAKSELF;
    [self.view addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [weakSelf.view endEditing:YES];
    }];
    [self tableViewAttributes];
}

-(void)setIsShowHead:(BOOL)isShowHead{
    _isShowHead = isShowHead;
    if (_isShowHead) {
        [self.tableView registerNib:[UINib nibWithNibName:@"HeaderFooterView" bundle:nil] forHeaderFooterViewReuseIdentifier:HeaderFooterViewIdentifier];
    }}
- (void)setHeadTitle:(NSString *)headTitle{
    _headTitle = headTitle;
    
}
- (void)tableViewAttributes{
    self.tableView.tableFooterView = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectZero];
    
    self.clearsSelectionOnViewWillAppear = NO;
    
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    
}





#pragma mark - Table view data source

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    HeaderFooterView *head = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HeaderFooterViewIdentifier];
    
    head.backgroundView = [[UIImageView alloc] initWithImage:[NHUtils imageWithColor:[UIColor appViewViewForHeaderInSection] size:CGSizeMake(511, 45) alpha:1]];
    [head setheadTitle:_headTitle];
    return head;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _row;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return _isShowHead?kscaleHeight(30.f):kscaleHeight(10.f);
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1f;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 15, 0, 15)];
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
